<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class ProductPhotoValidatorSchema extends sfValidatorSchema
{
  protected function configure($options = array(), $messages = array())
  {

    $this->addMessage('filename', 'The filename is required.');
  }

  protected function doClean($values)
  {
    $errorSchema = new sfValidatorErrorSchema($this);

    foreach($values as $key => $value)
    {

        $errorSchemaLocal = new sfValidatorErrorSchema($this);

      // filename is filled but no caption


      // caption is filled but no filename


      // no caption and no filename, remove the empty values
      if ($key == 'newPhotos' && $key['filename'] == '')
      {
        
       
         // $errorSchema->addError($errorSchemaLocal, $key);
          unset($values[$key]);
      }

      // some error for this embedded-form
      if (count($errorSchemaLocal))
      {
        $errorSchema->addError($errorSchemaLocal, (string) $key);
      }
      
    }

    // throws the error for the main form
    if (count($errorSchema))
    {
      throw new sfValidatorErrorSchema($this, $errorSchema);
    }

    return $values;

  }
}

